package com.xzm.project.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xzm.project.R;

import java.util.List;

public class ListViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> mList;


    public ListViewAdapter(Context mContext, List<String> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.view_list_item, parent, false);
            viewHolder.textView = convertView.findViewById(R.id.list_item_tv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.bindData(mList.get(position));
        return convertView;
    }

    private static class ViewHolder {
        private TextView textView;

        private void bindData(String str) {
            textView.setText(str);
        }
    }
}
